package cn.edu.zut.service.Impl;

import cn.edu.zut.dao.MessageDao;
import cn.edu.zut.domain.Message;
import cn.edu.zut.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;
    @Override
    public List<Message> findByUserId(String userId){ return messageDao.findByUserId(userId); }
    @Override
    public void add(Message message){ messageDao.add(message); }
    @Override
    public void update(Message message){ messageDao.update(message); }
    @Override
    public void deleteById(int _id){ messageDao.deleteById(_id); }
    @Override
    public Message findById(int _id){ return messageDao.findById(_id); }
    @Override
    public List<Message> findAllNoVis(String userId,String vis){
        return messageDao.findAllNoVis(userId,vis);
    }
    @Override
    public int findEmptyMessageId(){
        List<Message> list = messageDao.findAll();
        for(int i=0;i<list.size();i++){
            if(list.get(i).get_id()!=i)return i;
        }
        return list.size();
    }
}
